package com.olddriver.crm.service.impl;

import com.olddriver.crm.domain.ClientFail;
import com.olddriver.crm.domain.Employee;
import com.olddriver.crm.mapper.ClientFailMapper;
import com.olddriver.crm.page.PageResult;
import com.olddriver.crm.query.ClientFailQueryObject;
import com.olddriver.crm.service.IClientFailService;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.Date;

@Service
public class ClientFailServiceImpl implements IClientFailService {

    @Autowired
    private ClientFailMapper clientFailMapper;

    public int save(ClientFail clientFail){
        //设置录入时间,录入负责人在其它调用的service层做
        clientFail.setInputTime(new Date());
        Employee inputUser = (Employee) SecurityUtils.getSubject().getPrincipal();
        return clientFailMapper.save(clientFail);
    }

    public PageResult query(ClientFailQueryObject qo) {
        int total = clientFailMapper.queryTotal(qo);
        if (total == 0) {
            return new PageResult(total, Collections.emptyList());
        }
        return new PageResult(total, clientFailMapper.queryRows(qo));
    }
}
